//
//  SYSQLiteManager.swift
//  SingWeibo
//
//  Created by shiying on 16/1/3.
//  Copyright © 2016年 shiying. All rights reserved.
//

import UIKit

let T_Status = "T_Status"

class SYSQLiteManager: NSObject {

    // 单例
    static let sharedManager = SYSQLiteManager()
    
    // 数据库
    var dbQueue: FMDatabaseQueue
    
    private override init() {
        let documentPath = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true).last!
        let dbPath = (documentPath as NSString).stringByAppendingPathComponent("status.db")
        
        print("dbPath\(dbPath)")
        dbQueue = FMDatabaseQueue(path: dbPath)
        
        super.init()
        createTable(T_Status)
    }
    func createTable(tName: String) {
        // sql
        let sql = "CREATE TABLE IF NOT EXISTS \(tName) ( \n" +
        "statusId INTEGER NOT NULL, \n" +
        "status TEXT, \n" +
        "userId INTEGER, \n" +
        "PRIMARY KEY(statusId))"
        // 执行sql
        dbQueue.inDatabase { (db) -> Void in
            // 要执行的代码
            if db.executeUpdate(sql) {
                print("创建表成功")
            } else {
                print("创建表失败")
            }
        }
    
    
    
    }
    
}

































